import 'dart:convert';

class CityData {
  final int code;
  final String msg;
  final List<ProvinceData> data;

  CityData({this.code, this.msg, this.data});

  //JSON to model
  factory CityData.fromJson(Map<String, dynamic> json) {
    var dataJson = json['data'] as List;
    List<ProvinceData> dataList =
        dataJson.map((i) => ProvinceData.fromJson(i)).toList();

    return CityData(code: json['code'], msg: json['msg'], data: dataList);

  }

//model to json
  Map<String, dynamic> toJson() {
    final Map<String, dynamic> dataMap = new Map<String, dynamic>();

    dataMap['code'] = this.code;
    dataMap['msg'] = this.msg;
    if (data != null) dataMap['data'] = data.map((v) => v.toJson()).toList();

    return dataMap;
  }
}

class ProvinceData {
  final String code;
  final String name;
  final List<PchildsData> pchilds;

  ProvinceData({this.code, this.name, this.pchilds});

  factory ProvinceData.fromJson(Map<String, dynamic> json) {
    var pchildsJson = json['pchilds'] as List;
    List<PchildsData> pchildList =
        pchildsJson.map((i) => PchildsData.fromJson(i)).toList();

    return ProvinceData(
        code: json['code'], name: json['name'], pchilds: pchildList);
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> dataMap = new Map<String, dynamic>();

    dataMap['code'] = this.code;
    dataMap['name'] = this.name;
    if (pchilds != null)
      dataMap['pchilds'] = pchilds.map((v) => v.toJson()).toList();

    return dataMap;
  }
}

class PchildsData {
  final String code;
  final String name;
  final List<CchildsData> cchilds;

  PchildsData({this.code, this.name, this.cchilds});

  factory PchildsData.fromJson(Map<String, dynamic> json) {
    var cchildsListjson = json['cchilds'] as List;
    List<CchildsData> pchildList =
        cchildsListjson.map((i) => CchildsData.fromJson(i)).toList();
    return PchildsData(
        code: json['code'], name: json['name'], cchilds: pchildList);
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> dataMap = new Map<String, dynamic>();

    dataMap['code'] = this.code;
    dataMap['name'] = this.name;
    if (cchilds != null)
      dataMap['cchilds'] = cchilds.map((v) => v.toJson()).toList();

    return dataMap;
  }
}

class CchildsData {
  final String code;
  final String name;

  CchildsData({this.name, this.code});

  factory CchildsData.fromJson(Map<String, dynamic> json) {
    return CchildsData(code: json['code'], name: json['name']);
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> dataMap = new Map<String, dynamic>();
    dataMap['code'] = this.code;
    dataMap['name'] = this.name;
    return dataMap;
  }
}
